<template>
  <div style="margin-top: 20px">
    <a-form :model="form" :style="{ width: '600px' }">
      <a-form-item>
        <h1 style="font-size: 20px">发起测试任务，生产环境中由ERP产品开发模块远程触发</h1>
      </a-form-item>
      <a-form-item field="name" label="Title">
        <a-input v-model="form.name" placeholder="Please Input Title" />
      </a-form-item>
      <a-form-item field="name" label="Remarks">
        <a-input v-model="form.remarks" placeholder="Please Input Remarks" />
      </a-form-item>
      <a-form-item field="name" label="费用说明">
        <div>如果报价，则默认从成本账户中扣除</div>
      </a-form-item>
      <a-form-item field="name" label="图种类">
        <a-checkbox v-model="form.task1"> A+图片 </a-checkbox>
        <a-input-number v-model="form.task1Price" :style="{ width: '100px' }" placeholder="价格" :min="0.01" :max="100" />
        <a-checkbox v-model="form.task2"> 主图 </a-checkbox>
        <a-input-number v-model="form.task2Price" :style="{ width: '100px' }" placeholder="价格" :min="0.01" :max="100" />
        <a-checkbox v-model="form.task3"> 场景图 </a-checkbox>
        <a-input-number v-model="form.task3Price" :style="{ width: '100px' }" placeholder="价格" :min="0.01" :max="100" />
        <a-checkbox v-model="form.task4"> 精修图 </a-checkbox>
        <a-input-number v-model="form.task4Price" :style="{ width: '100px' }" placeholder="价格" :min="0.01" :max="100" />
      </a-form-item>
      <a-form-item>
        <a-button type="outline" size="mini" status="success" @click="submitTask">Submit Image Task (For Test)</a-button>
      </a-form-item>
    </a-form>
  </div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { createTestTask } from '@/api/task'
import { Message } from '@arco-design/web-vue'
let form = ref()
form.value = {}
const submitTask = async () => {
  let items: Object[] = []
  if (form.value.task1) {
    items.push({ type: 'amz_pic_A+', code: new Date().getTime(), subject: 'A+图', budgetPrice: form.value.task1Price, budgetWalletType: 'amb-cost-cny' })
  }
  if (form.value.task2) {
    items.push({ type: 'amz_pic_main_pic', code: new Date().getTime(), subject: '主图', budgetPrice: form.value.task2Price, budgetWalletType: 'amb-cost-cny' })
  }
  if (form.value.task3) {
    items.push({ type: 'amz_pic_senec', code: new Date().getTime(), subject: '场景图', budgetPrice: form.value.task3Price, budgetWalletType: 'amb-cost-cny' })
  }
  if (form.value.task4) {
    items.push({ type: 'amz_pic_jx', code: new Date().getTime(), subject: '精修图', budgetPrice: form.value.task4Price, budgetWalletType: 'amb-cost-cny' })
  }
  let param = {
    subject: form.value.name,
    remarks: form.value.remarks,
    items: items,
  }
  let rs = await createTestTask(param)

  if (rs?.data?.taskGroupId) {
    Message.success('任务发布成功')
  } else {
    Message.error('任务发布可能出错了')
  }
}
</script>